﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Dimok.Dictionary {
	public class CaseInsensitiveStringDictionary<TValue> : Dictionary<string, TValue> {
		public CaseInsensitiveStringDictionary() : base(new CaseInsensitiveStringEqualityComparer()) { }
	}

	public class CaseInsensitiveStringEqualityComparer : IEqualityComparer<string> {
		public CaseInsensitiveComparer myComparer;

		public CaseInsensitiveStringEqualityComparer() {
			myComparer = CaseInsensitiveComparer.DefaultInvariant;
		}

		public bool Equals(string x, string y) {
			if (myComparer.Compare(x, y) == 0) {
				return true;
			} else {
				return false;
			}
		}

		public int GetHashCode(string obj) {
			return obj.ToLower().GetHashCode();
		}
	}
	public class CaseInsensitiveEqualityComparer : IEqualityComparer {
		public CaseInsensitiveComparer myComparer;

		public CaseInsensitiveEqualityComparer() {
			myComparer = CaseInsensitiveComparer.DefaultInvariant;
		}

		public CaseInsensitiveEqualityComparer(System.Globalization.CultureInfo myCulture) {
			myComparer = new CaseInsensitiveComparer(myCulture);
		}

		public new bool Equals(object x, object y) {
			if (myComparer.Compare(x, y) == 0) {
				return true;
			} else {
				return false;
			}
		}

		public int GetHashCode(object obj) {
			return obj.ToString().ToLower().GetHashCode();
		}
	}
}
